import datetime
import logging

from egpylons.lib.base import *

log = logging.getLogger(__name__)

class ToolkitController(BaseController):

    def index(self):
        return render('toolkit.index')

    def blog_add(self):
        return render('toolkit.add')

    def blog_add_process(self):
        # Create a new Blog object and populate it.
        newpost = model.Blog()
        newpost.date = datetime.datetime.now()
        newpost.content = request.params['content']
        newpost.author = request.params['author']
        newpost.subject = request.params['subject']
        # I didn't set ID because it will get an autoincrement value.
        
        # Attach the object to the session.
        model.Session.save(newpost)

        # Commit the transaction.
        # (This sends the SQL INSERT command due to autoflushing.)
        model.Session.commit()

        # Redirect to the blog home page.
        #redirect_to(controller="blog", action="index")  # This isn't working for me.
        redirect_to("/blog")

